home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / chat / reflect.000 / reflect / 3.0b3 / refutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  4.8 KB  |  171 lines

  1. /*
  2.  
  3. Copyright 1993, 1994, Cornell University
  4.  
  5. Cornell hereby grants permission to use, copy, modify, and distribute this program for any purpose 
  6. and without fee, provided that these copyright and permission notices appear on all copies and 
  7. supporting documentation, the name of Cornell not be used in advertising or publicity pertaining 
  8. to distribution of the program without specific prior permission, notice be given in supporting 
  9. documentation that copying and distribution is by permission of Cornell.  CORNELL MAKES NO 
  10. REPRESENTATIONS OR WARRANTEES, EXPRESS OR IMPLIED.  By way of example, but not limitation, 
  11. CORNELL MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR 
  12. PURPOSE OR THAT THE USE OF THIS SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, 
  13. TRADEMARKS, OR OTHER RIGHTS.  Cornell shall not be held liable for any liability with respect to 
  14. any claim by the user or any other party arising from use of the program.
  15.  
  16. This material is partially based on work sponsored by the National Science Foundation under Cooperative 
  17. Agreement No. NCR-9318337.  The government has certain rights in this material.
  18.  
  19. */
  20.  
  21.  
  22.  
  23. #include <stdio.h>
  24. #include <signal.h>
  25. #include <errno.h>
  26. #include <sys/types.h>
  27. #include <sys/socket.h>
  28.  
  29. #ifndef LINUX
  30. #include <sys/socketvar.h>
  31. #endif
  32.  
  33. #include <netinet/in.h>
  34.  
  35. #include "reflect.h"
  36. #include "refmon.h"
  37. #include "globals.h"
  38.  
  39. /* 
  40.    initialize the list of servers from whom we hope to attain a stream of 
  41.    Blind Carbon Copy video
  42. */
  43.  
  44. open_bcc_servers()
  45. {
  46.     VideoPacketHeader pkt;
  47.     client *ctmp,ctmp1;
  48.     short cnt,*id;
  49.  
  50.     for (cnt = 0; cnt < bcc_srv_cnt; cnt++)
  51.     {
  52.        pkt.routing.src.family = htons(kReflector);
  53.        bcopy(&myaddr.sin_addr.s_addr,&pkt.routing.src.addr,4);
  54.        pkt.routing.src.port = htons(VID_PORT);
  55.  
  56.        pkt.routing.dest.family = htons(kReflector);
  57.        bcopy(&bcc_server_list[cnt],&pkt.routing.dest.addr,4);
  58.        pkt.routing.dest.port = htons(VID_PORT);
  59.    
  60.        pkt.seqNum = 0;
  61.        pkt.dataType = htons(kConfigRefType);
  62.        pkt.len = htons(sizeof(VideoPacketHeader)+2);
  63.        pkt.message = htons(kBCCOpen);
  64.        id = (short *) ((char *) &pkt + HEADERLEN);
  65.        *id = bcc_server_list_id[cnt];
  66.  
  67.  
  68. #ifdef DEBUG
  69.        if (debug)
  70.           printf("sending BCC server keep alive ");
  71. #endif
  72.  
  73.        /* 
  74.           if the server is already in our client list. use its actual client
  75.           ptr, else just us a temporary one for now
  76.        */
  77.  
  78.        if ((ctmp = find_client(bcc_server_list[cnt])) == NULL)
  79.        {
  80.           bcopy(&bcc_server_list[cnt],&ctmp1.clnt_addr.addr,4);
  81.           ctmp1.clnt_addr.family = AF_INET;
  82.           ctmp1.clnt_addr.port = htons(VID_PORT);
  83.           ctmp1.clnt_flags = BCC_SERVER;
  84.           write_pkt(&pkt,&ctmp1);
  85.        }
  86.        else
  87.           write_pkt(&pkt,ctmp);
  88.     }
  89. }
  90.  
  91. open_ucast_ref()
  92. {
  93.     VideoPacketHeader pkt;
  94.     client *ctmp,ctmp1;
  95.     short cnt;
  96.  
  97.     for (cnt = 0; cnt < ref_ucast_cnt; cnt++)
  98.     {
  99.        pkt.routing.src.family = htons(kReflector);
  100.        bcopy(&myaddr.sin_addr.s_addr,&pkt.routing.src.addr,4);
  101.        pkt.routing.src.port = htons(VID_PORT);
  102.  
  103.        pkt.routing.dest.family = htons(kReflector);
  104.        bcopy(&bcc_server_list[cnt],&pkt.routing.dest.addr,4);
  105.        pkt.routing.dest.port = htons(VID_PORT);
  106.    
  107.        pkt.seqNum = 0;
  108.        pkt.dataType = htons(kConfigRefType);
  109.        pkt.len = htons(sizeof(VideoPacketHeader));
  110.        pkt.message =  htons(kREFOpen);
  111.  
  112.  
  113. #ifdef DEBUG
  114.        if (debug)
  115.           printf("sending unicast server keep alive ");
  116. #endif
  117.  
  118.        /* 
  119.           if the server is already in our client list. use its actual client
  120.           ptr, else just us a temporary one for now
  121.        */
  122.  
  123.        if ((ctmp = find_client(ref_ucast_list[cnt])) == NULL)
  124.        {
  125.           bcopy(&ref_ucast_list[cnt],&ctmp1.clnt_addr.addr,4);
  126.           ctmp1.clnt_addr.family = AF_INET;
  127.           ctmp1.clnt_addr.port = htons(VID_PORT);
  128.           ctmp1.clnt_flags = REF3_SERVER;
  129.           write_pkt(&pkt,&ctmp1);
  130.        }
  131.        else
  132.           write_pkt(&pkt,ctmp);
  133.     }
  134. }
  135.  
  136.  
  137. rf_mcast_wrt(vidptr)
  138.     VideoPacketHeader   *vidptr;
  139.  
  140. {
  141. #ifdef DEBUG
  142.        if (debug)
  143.           printf("Multicasting (for RF) to %s\n",inet_ntoa(rfout_mcast.sin_addr));
  144. #endif
  145.  
  146.     pkts_out++;
  147.     bytes_out += ntohs(vidptr->len);
  148.  
  149.     if (sendto(rfout_mcast_sock,vidptr,ntohs(vidptr->len),0,&rfout_mcast,sizeof(struct sockaddr_in)) != ntohs(vidptr->len))
  150.        dolog("mcast sendto error");
  151.  
  152. }
  153.  
  154. inout_mcast_wrt(vidptr)
  155.     VideoPacketHeader   *vidptr;
  156.  
  157. {
  158. #ifdef DEBUG
  159.        if (debug)
  160.           printf("Multicasting (to group) to %s\n",inet_ntoa(inout_mcast.sin_addr));
  161. #endif
  162.  
  163.     pkts_out++;
  164.     bytes_out += ntohs(vidptr->len);
  165.  
  166.     if (sendto(inout_mcast_sock,vidptr,ntohs(vidptr->len),0,&inout_mcast,sizeof(struct sockaddr_in)) != ntohs(vidptr->len))
  167.        dolog("mcast sendto error");
  168.  
  169. }
  170.  
  171.